﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service.ReliefInfo
{
    public partial class ReliefInfoRemark : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
                //this.labUSERNAME.Text = ut.U_CName;
                //this.labUSERNO.Text = ut.U_UserNO;
                bindReliefLog();
            }
        }
        /// <summary>
        /// 绑定交接班信息
        /// </summary>
        private void bindReliefLog()
        {
            //its_ReliefLog rl = new its_ReliefLog();
            //rl.USERNO = this.labUSERNO.Text;
            //its_ReliefLogCs rlCs = new its_ReliefLogCs();
            //ArrayList arr = rlCs.ReliefLog_Select(rl, this.PUReliefInfo.CurrentPageIndex,this.PUReliefInfo.PageSize);
            //this.GVReliefInfo.DataSource = arr[1] as DataTable;
            //this.GVReliefInfo.DataBind();
            //this.PUReliefInfo.RecordCount = (int)arr[0];
            string strWhere="where IsDel=0 ";
            if (this.txtUSERNO.Text.Trim() != "")
            {
                strWhere += " and USERNO like '%" + this.txtUSERNO.Text.Trim().Replace("'", "''") + "%' "; 
            }
            if (txtUSERNAME.Text.Trim() != "")
            {
                strWhere += " and USERNAME like '%" + this.txtUSERNAME.Text.Trim().Replace("'", "''") + "%' ";
            }
            if (this.rdbsRELIEFNO.SelectedValue != "-1")
            {
                strWhere += " and RELIEFNO =" + this.rdbsRELIEFNO.SelectedValue + " ";
            }
            if (txtBegin.Text.Trim() != "")
            {
                strWhere += " and RELIEFDAT>='" + txtBegin.Text.Trim() + "' ";
            }

            if (txtEnd.Text.Trim() != "")
            {
                strWhere += " and RELIEFDAT<'" + DateTime.Parse(txtEnd.Text.Trim()).AddDays(1).ToString() + "' ";
            }
            if (this.dropImport.SelectedValue != "-1")
            {
                strWhere += " and Import=" + dropImport.SelectedValue;
            }


            AllSeach _AllSeach = new AllSeach();
            DataSet ds = _AllSeach.SupesoftPage("its_ReliefLog", "UID, USERNO, USERNAME, dbo.its_RELIEFNO(RELIEFNO) as RELIEFNOName,RELIEFNO , RELIEFDAT, FILLINDAT,Import, CONTENT,Temp1", this.PUReliefInfo.PageSize, this.PUReliefInfo.CurrentPageIndex, strWhere, "UID", "1");
           DataTable dt = ds.Tables[0];
           DataTable dtCount = ds.Tables[1];
           this.GVReliefInfo.DataSource = dt;
           this.GVReliefInfo.DataBind();
           this.PUReliefInfo.RecordCount = int.Parse(dtCount.Rows[0][1].ToString());
        }
        //protected void btnSave_Click(object sender, EventArgs e)
        //{
        //    if (this.txtRELIEFDAT.Text.Trim() == "")
        //    {
        //        this.ClientScript.RegisterStartupScript(this.GetType(), "NoDate", "<script>alert('请填写交接班时间！');</script>");
        //        return;
        //    }
        //    its_ReliefLog rl = new its_ReliefLog();
        //    rl.USERNAME = this.labUSERNAME.Text;
        //    rl.USERNO = this.labUSERNO.Text;
        //    rl.RELIEFDAT = (DateTime)Common.sink(txtRELIEFDAT.UniqueID, MethodType.Post, 50, 0, DataType.Dat);
        //    rl.RELIEFNO = int.Parse(this.rdbRELIEFNO.SelectedValue);
        //    rl.CONTENT = this.txtCONTENT.Text.Trim();
        //    if (cbImport.Checked)
        //    {
        //        rl.Import = 1;
        //    }
        //    else
        //    {
        //        rl.Import = 0;
        //    }
        //    its_ReliefLogCs rlCs = new its_ReliefLogCs();
        //    rlCs.ReliefLog_Add(rl);
        //    EventMessage.MessageBox(1, "保存成功", "交接班保存成功!", Icon_Type.OK, this.Request.Url.ToString());
        //    try
        //    {
        //        this.txtCONTENT.Text = "";
        //        bindReliefLog();
        //    }
        //    catch (Exception ex)
        //    {
        //        this.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('保存失败，请联系管理员！');</script>");
        //        FileTxtLogs.WriteLog(ex.Message);
        //    }


        //}

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow gr in this.GVReliefInfo.Rows)
            {
                
                if (int.Parse(((Label)gr.FindControl("labUID")).Text) == int.Parse(this.txtEditUID.Text))
                {
                    labEditUSERNO.Text = ((HyperLink)gr.FindControl("labUSERNO")).Text;
                    labEditUSERNAME.Text = ((HyperLink)gr.FindControl("labUSERNAME")).Text;
                    rdbEditRELIEFNO.SelectedValue = ((Label)gr.FindControl("labRELIEFNO")).Text;
                    labEditRELIEFNO.Text = rdbEditRELIEFNO.SelectedItem.Text;

                    txtEditRELIEFDAT.Text = ((Label)gr.FindControl("labRELIEFDAT")).Text.Replace("年","-").Replace("月","-").Replace("日","");
                    labEditFILLINDAT.Text = ((Label)gr.FindControl("labFILLINDAT")).Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
                    txtEditCONTENT.Text = ((Label)gr.FindControl("labCONTENT")).Text.Replace("<br/>","\r\n");
                    txtTemp1.Text = ((Label)gr.FindControl("labTemp1")).Text.Replace("<br/>", "\r\n");
                    //if (labEditUSERNO.Text.Trim() != this.labUSERNO.Text.Trim())
                    //{
                    //    btnEditSave.Enabled = false;
                    //    btnDel.Enabled = false;
                    //    btnDel.Attributes.Remove("onclick");
                    //}
                    //else
                    //{
                    //    btnEditSave.Enabled = true;
                    //    btnDel.Enabled = true;
                    //    btnDel.Attributes.Add("onclick", "return confirm('您确定要删除该记录吗？');");
                    //}
                    if (((Label)gr.FindControl("labImport")).Text == "1")
                    {
                       
                        labEditImport.Text = "是";
                    }
                    else
                    {
                      
                        labEditImport.Text = "否";
                    }
                    break;
                }
            }
            this.ClientScript.RegisterStartupScript(this.GetType(), "Edit", "<script>showTabEdit();</script>");
        }

        protected void PUReliefInfo_PageChanged(object sender, EventArgs e)
        {
            bindReliefLog();
        }

        protected void btnEditSave_Click(object sender, EventArgs e)
        {
            its_ReliefLog rl = new its_ReliefLog();
            rl.UID = int.Parse(this.txtEditUID.Text);
            rl.Temp1 = this.txtTemp1.Text.Trim();

            its_ReliefLogCs rlCs = new its_ReliefLogCs();
            rlCs.ReliefLog_UpdateTemp1(rl);
            bindReliefLog();
        }

        protected void GVReliefInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                ((Label)e.Row.FindControl("labCONTENT")).Text = ((Label)e.Row.FindControl("labCONTENT")).Text.Replace("\r\n", "<br/>");
                ((Label)e.Row.FindControl("labTemp1")).Text = ((Label)e.Row.FindControl("labTemp1")).Text.Replace("\r\n", "<br/>");
                if (((Label)e.Row.FindControl("labImport")).Text == "1")
                {
                    e.Row.ForeColor = System.Drawing.Color.Red;
                }
            }
        }

     
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            this.PUReliefInfo.CurrentPageIndex = 0;
            bindReliefLog();
            this.TabOptionWebControls1.SelectIndex = 0;
        }

       
    }
}
